
<% include("../common/head.html"){} %>

<script>
$("#permission_submit_search").click(function () {
                $('#permissionDataGrid').datagrid('load',{
					permission: $('#permission').val()
				});
            });
</script>

<div class="easyui-panel" data-options="fit:true,boarder:false">
	<!--<table class="easyui-datagrid" id="permissionDataGrid" data-options="url:'/permission/query',
		rownumbers:true,pagination:true,pageNumber:1,pageSize:20,pagePosition:'bottom',
		fit:true,toolbar:'#permission_search',singleSelect:true,showFooter:true">
		<thead>
			<tr>
				<th data-options="field:'id',width:100">权限编号</th>
				<th data-options="field:'permission',width:100">权限名称</th>
				<th data-options="field:'description'">权限描述</th>
			</tr>
		</thead>
	</table>-->
	
	<table title="权限列表" id="dataGrid" class="easyui-treegrid" 
		data-options="url:'/permission/allPermission',method:'get',rownumbers: 	true,toolbar:'#permission_search',singleSelect:true,showFooter:true,idField:'id',treeField:'text' ">
<thead>
	<tr>
		<th data-options="field:'text'">权限描述</th>
		<th data-options="field:'permission',width:100">权限名称</th>
	</tr>
</thead>
</table>
	
	<div id ="permission_search" class="tableSearch">
		<input type="text" id="permission" size=10  placeholder="角色名称" />
    	<button class="btn btn-default" id="permission_submit_search">查 询</button>
    	<button class="btn btn-default" onclick="resetForm();">重 置</button>
    	<br/>
		<% if(so.hasRole("admin")){%>
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="addPermission()">新增权限</a> 
		<%}%>
		<% if(so.hasRole("admin")){%>
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editPermission()">修改权限</a>
		<%}%>
		<% if(so.hasRole("admin")){%>
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removePermission()">删除权限</a>
		<%}%> 
	</div>


<div id="dlg" class="easyui-dialog" style="width:400px;height:160px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" >
        	<div class="fitem">
                <label>从属画面:</label>
                <input id="parent_id" class="easyui-combobox" name="parent_id"   
					data-options="valueField:'id',textField:'description',url:'/permission/rootPermission'" >
            </div>
        	<div class="fitem">
                <label>权限描述:</label>
                <input name="text" class="easyui-textbox" required="true" >
            </div>
            <div class="fitem">
                <label>权限名称:</label>
                <input name="permission" class="easyui-textbox" required="true" >
            </div>
        </form>
</div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="savePermission()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <script type="text/javascript">
        var url;
        function addPermission(){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增权限');
            $('#fm').form('clear');
            url = '/permission/save';
        }
        function editPermission(){
            var row = $('#dataGrid').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','修改权限');
                $('#fm').form('load',row);
                url = '/permission/update?id='+row.id;
            }
        }
        function savePermission(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(result){
                    var result = eval('('+result+')');
                    if (result.success){
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dataGrid').treegrid('load', {});
                    } else {
                     	$.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    }
                }
            });
        }
        function removePermission(){
            var row = $('#dataGrid').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','确认删除权限 '+row.permission,function(r){
                    if (r){
                        $.post('/permission/remove',{id:row.id},function(result){
                            if (result.success){
                                $('#dataGrid').treegrid('load', {});
                            } else {
                                $.messager.show({    // show error message
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
    </script>

<% include("../common/footer.html"){} %>